define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        virtual_url: 'mall.virtual_order/virtualOrder',
        detail_url: 'mall.order/detail',
        add_url: 'mall.virtual_order/add',
        hide_url: 'mall.virtual_order/hide',
        show_url: 'mall.virtual_order/show',
    };

    var Controller = {
        virtualOrder: function () {
            ea.table.render({
                init: init,
                url: 'virtualOrder',
                toolbar: ['refresh',
                    [{
                        text: '添加虚拟订单',
                        url: init.add_url,
                        method: 'open',
                        auth: 'add',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-plus ',
                        extend: 'data-full="false"',
                    }]
                ],
                cols: [[
                    {field: 'order_no', title: '订单号'},
                    {field: 'collage.collage_no', title: '拼团号'},
                    {field: 'user.name', title: '用户名'},
                    {field: 'goods_name', title: '商品名'},
                    {field: 'pay_price', title: '实际付款金额', templet: ea.table.price, search: false},

                    {
                        field: 'order_status',
                        title: '订单状态',
                        selectList: {
                            0: '未支付',
                            10: '拼团中',
                            20: '已取消',
                            30: '拼团成功',
                            40: '拼团失败',
                            50: '已发货',
                            60: '已完成',
                            70: '退款'
                        },
                        // templet: ea.table.switch
                    },
                    {field: 'create_time', title: '创建时间', search: 'false'},
                    {
                        field: 'ea_mall_order-create_time_left',
                        minWidth: 80,
                        title: '创建开始时间',
                        search: 'rangeLeft',
                        hide: true,
                        searchOp: 'rangeLeft'
                    },
                    {
                        field: 'ea_mall_order-create_time_right',
                        minWidth: 80,
                        title: '创建结束时间',
                        search: 'rangeRight',
                        hide: true,
                        searchOp: 'rangeRight'
                    },
                    {
                        width: 250, title: '操作', templet: function (row) {
                            var operat = [ // 操作按钮
                                [{
                                    text: '订单详情',
                                    url: init.detail_url,
                                    method: 'open',
                                    field: 'id',
                                    auth: 'detail',
                                    class: 'layui-btn layui-btn-xs layui-btn-success',
                                    extend: 'data-full="true"',
                                }]
                            ]
                            var order_status = row.order_status
                            var collage_status = row.collage.status
                            if (order_status === 10 && collage_status === 1) {
                                operat.push(
                                    [
                                        {
                                            class: 'layui-btn layui-btn-success layui-btn-xs',
                                            method: 'get',
                                            field: 'id',
                                            icon: '',
                                            text: '隐藏',
                                            title: '确认隐藏',
                                            auth: 'hide',
                                            url: init.hide_url,
                                            extend: ""
                                        }
                                    ]
                                )
                            }
                            if (order_status === 10 && collage_status === 0) {
                                operat.push(
                                    [
                                        {
                                            class: 'layui-btn layui-btn-success layui-btn-xs',
                                            method: 'get',
                                            field: 'id',
                                            icon: '',
                                            text: '显示',
                                            title: '确认显示',
                                            auth: 'hide',
                                            url: init.show_url,
                                            extend: ""
                                        }
                                    ]
                                )
                            }
                            return ea.table.tool(row, {
                                init, // 初始化的数据变量
                                operat: operat
                            }); // 其他状态下 没有操作按钮返回空字符串即可
                        }
                    },
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
    };
    return Controller;
});